package model

import (
	"gorm.io/gorm"
	"group_-no.2/utils/errmsg"
)

type Profile struct {
	User User `gorm:"foreignkey:UserID"`
	gorm.Model
	Sex      string `gorm:"type:varchar(10)" json:"sex"`
	Name     string `gorm:"type:varchar(255)" json:"name"`
	Desc     string `gorm:"type:text" json:"desc"`
	QQ       string `gorm:"type:varchar(10)" json:"qq"`
	Wechat   string `gorm:"type:varchar(50)" json:"wechat"`
	Email    string `gorm:"type:varchar(50)" json:"email"`
	Img      string `gorm:"type:varchar(200)" json:"img"`
	Location string `gorm:"type:varchar(100)" json:"location"`
	UserID   uint   `gorm:"type:int;not null" json:"user_id"`
}

func GetProfile(id uint) (Profile, int) {
	var profile Profile
	err := db.Where("id = ?", id).First(&profile).Error
	if err != nil {
		return Profile{}, errmsg.ERROR
	}
	return profile, errmsg.SUCCESS
}

func UpdateProfile(id uint, data *Profile) int {
	var profile Profile
	err := db.Model(&profile).Where("id = ?", id).Updates(data).Error
	if err != nil {
		return errmsg.ERROR
	}
	return errmsg.SUCCESS
}
